package net.maku.custom.biza.service.followup.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import java.util.Date;
import java.util.List;
import lombok.AllArgsConstructor;
import net.maku.custom.biza.controller.followup.query.FollowUpDetailsQuery;
import net.maku.custom.biza.controller.followup.vo.FollowUpDetailsVO;
import net.maku.custom.biza.mapper.followup.FollowUpDetailsConvert;
import net.maku.custom.biza.mapper.followup.FollowUpDetailsDao;
import net.maku.custom.biza.pojo.followup.FollowUpDetailsEntity;
import net.maku.custom.biza.service.followup.FollowUpDetailsService;
import net.maku.framework.common.page.PageResult;
import net.maku.framework.common.service.impl.BaseServiceImpl;
import net.maku.framework.security.user.SecurityUser;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 跟进明细
 *
 * @author NULL babamu@126.com
 * @since 1.0.0 2022-07-11
 */
@Service
@AllArgsConstructor
public class FollowUpDetailsServiceImpl extends BaseServiceImpl<FollowUpDetailsDao, FollowUpDetailsEntity> implements
        FollowUpDetailsService {

    @Override
    public PageResult<FollowUpDetailsVO> page(FollowUpDetailsQuery query) {
        IPage<FollowUpDetailsEntity> page1 = getPage(query);
        List<FollowUpDetailsVO> followUpDetailsVOList = baseMapper.selectRelList(page1, query);

        return new PageResult<>(followUpDetailsVOList, page1.getTotal());
    }

    @Override
    public FollowUpDetailsVO selectRelById(Long id) {
        return baseMapper.selectRelById(id);
    }

    private QueryWrapper<FollowUpDetailsEntity> getWrapper(FollowUpDetailsQuery query){
        QueryWrapper<FollowUpDetailsEntity> wrapper = new QueryWrapper<>();

        return wrapper;
    }

    @Override
    public void save(FollowUpDetailsVO vo) {
        FollowUpDetailsEntity entity = FollowUpDetailsConvert.INSTANCE.convert(vo);
        entity.setCreator(SecurityUser.getUserId());
        entity.setCreateTime(new Date());
        baseMapper.insert(entity);
    }

    @Override
    public void update(FollowUpDetailsVO vo) {
        FollowUpDetailsEntity entity = FollowUpDetailsConvert.INSTANCE.convert(vo);
        entity.setUpdater(SecurityUser.getUserId());
        entity.setUpdateTime(new Date());
        updateById(entity);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void delete(List<Long> idList) {
        removeByIds(idList);
    }

}